package com.sx.micowell.module.countdown

import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.example.mvvm.base.ContainerActivity
import com.example.mvvm.base.data.DataBindingConfig
import com.gyf.immersionbar.ImmersionBar
import com.miloyu.modelnet.response.log
import com.sx.micowell.BR
import com.sx.micowell.R
import com.sx.micowell.databinding.FragPlayCountdownBinding
import com.sx.micowell.framework.app.IntentKey
import com.sx.micowell.framework.app.MyFragment
import com.sx.micowell.framework.arouth.RouteManager
import com.sx.micowell.framework.arouth.RoutePath.Companion.PLAY_COUNT_DOWN
import com.sx.micowell.framework.model.PlayCountDownModel
import com.sx.micowell.framework.model.TrainModel
import com.sx.widget.view.MyCountTimer
import com.tuya.smart.home.sdk.TuyaHomeSdk


/**
 * @Description
 * @Author 梁浩文
 * @Date 2021/9/1 16:25
 */
@Route(path = PLAY_COUNT_DOWN)
class FragPlayCountDownFragment : MyFragment<FragPlayCountdownBinding, ContainerActivity>() {

    override fun getDataBindingConfig(): DataBindingConfig =
        DataBindingConfig(R.layout.frag_play_countdown,BR.viewModel,viewModel)

    @Autowired(name = IntentKey.TYPE)
    @JvmField
    var type: Int = 0

    @Autowired(name = IntentKey.DATA)
    @JvmField
    var data: String = ""

    private val viewModel: PlayCountDownModel by lazy {
        getFragmentScopeViewModel(PlayCountDownModel::class.java)
    }

    override fun initView() {
        myActivity.enableBack = false
        ImmersionBar.with(this).init()
        //倒计时总时间为10S，时间防止从9s开始显示
        //倒计时总时间为10S，时间防止从9s开始显示
        val myCountTimer = MyCountTimer(4000, 1000, binding.btnCountTimer, "Go")
        myCountTimer.setCallBackCount {
            HANDLER.postDelayed({
                if (type == 1) {
                    RouteManager.getInstance().intentSportActivity(data)
                }else{
                    viewModel.context.startContainerFragment(RouteManager.getInstance().getDeviceBindListFragment())
                }
                activity?.finish()
            }, 400)
        }
        myCountTimer.start()
    }


        override fun initData() {
            if (type == 1) {
                viewModel.cashLoad(data)
            }
        }
    }